package com.hntest.controller;

import com.hntest.entity.LoginInfo;
import com.hntest.entity.Pager;
import com.hntest.entity.RechargeOffline;
import com.hntest.service.RechargeOfflineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller("rechargeOfflineController")
public class RechargeOfflineController {

    @Autowired
    private RechargeOfflineService rechargeOfflineService;

    public void setRechargeOfflineService(RechargeOfflineService rechargeOfflineService) {
        this.rechargeOfflineService = rechargeOfflineService;
    }

    @RequestMapping(value = "/rechargeOfflineSelect", method = {RequestMethod.GET, RequestMethod.POST})
    public String select(Pager pager, RechargeOffline rechargeOffline, ModelMap modelMap, HttpServletRequest request){
        String time1=request.getParameter("time1");
        String time2=request.getParameter("time2");


        System.out.println("-----------------"+rechargeOffline.getState());
        List<RechargeOffline> list=rechargeOfflineService.getListByPage(pager, rechargeOffline,time1,time2);

        System.out.println("-----------------"+list);
        modelMap.put("list", list);
        modelMap.put("pager",pager);
        modelMap.put("rechargeOffline",rechargeOffline);
        modelMap.put("time1",time1);
        modelMap.put("time2",time2);
        modelMap.put("stateAll", rechargeOfflineService.getAllState());
        return "/rechargeOfflineSelect";
    }

    @RequestMapping(value = "/admin/rechargeOfflineSelect", method = {RequestMethod.GET, RequestMethod.POST})
    public String selectRechargeOffline(Pager pager, RechargeOffline rechargeOffline, ModelMap modelMap, HttpServletRequest request){
        String time1=request.getParameter("time1");
        String time2=request.getParameter("time2");


        System.out.println("-----------------"+rechargeOffline.getState());
        List<RechargeOffline> list=rechargeOfflineService.getListByPage(pager, rechargeOffline,time1,time2);

        System.out.println("-----------------"+list);
        modelMap.put("list", list);
        modelMap.put("pager",pager);
        modelMap.put("rechargeOffline",rechargeOffline);
        modelMap.put("time1",time1);
        modelMap.put("time2",time2);
        modelMap.put("stateAll", rechargeOfflineService.getAllState());
        return "/admin/rechargeOfflineSelect";
    }

    @RequestMapping("/toInsertRechargeOffline")//去往新增页面(得到银行下拉框的值)
    public String toInsert(ModelMap modelMap){
        modelMap.put("stateAll", rechargeOfflineService.getAllState());
        return "rechargeOffline";
    }

    @RequestMapping("/doInsertRechargeOffline")//提交新增数据，成功后重定向到分页查询
    public String doInsert(RechargeOffline rechargeOffline){
        int n=rechargeOfflineService.insert(rechargeOffline);
        if(n>0)
            return "redirect:/rechargeOfflineSelect?op=insertYes";
        else
            return "redirect:/rechargeOfflineSelect?op=insertNo";
    }

    @RequestMapping("/toUpdateRechargeOffline/{cbiid}")//根据学号查询出原始学生信息，然后把信息转发到修改页面
    public String toUpdate(@PathVariable(value="cbiid") int cbiid, ModelMap modelMap){
        RechargeOffline rechargeOffline=rechargeOfflineService.getRechargeOfflineById(cbiid);
        modelMap.put("old", rechargeOffline);//
        return "updateRechargeOffline";
    }

    @RequestMapping("/doUpdateRechargeOffline")//提交更新后的数据，成功后重定向到分页查询
    public String doUpdate(RechargeOffline rechargeOffline){
        int n=rechargeOfflineService.update(rechargeOffline);
        if(n>0)
            return "redirect:/admin/selectRechargeOffline?op=updateYes";
        else
            return "redirect:/admin/selectRechargeOffline?op=updateNo";
    }


}
